{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "777\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mIndexError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[6], line 16\u001B[0m\n\u001B[0;32m     13\u001B[0m \u001B[38;5;66;03m# 过滤治疗方式 = 保守治疗\u001B[39;00m\n\u001B[0;32m     14\u001B[0m conservative \u001B[38;5;241m=\u001B[39m [item \u001B[38;5;28;01mfor\u001B[39;00m item \u001B[38;5;129;01min\u001B[39;00m res[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mdata\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;28;01mif\u001B[39;00m item\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m治疗方式\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m保守治疗\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[1;32m---> 16\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[43mconservative\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m诊断编码\u001B[39m\u001B[38;5;124m'\u001B[39m])\n",
      "\u001B[1;31mIndexError\u001B[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "import json\n",
    "from catalog.dip_catalog import DipCatalog\n",
    "   \n",
    "\n",
    "dipCatalog = DipCatalog()\n",
    "core_catalog_json =dipCatalog.load_core_catalog('诊断名称','腔隙性脑梗死（急性期）')\n",
    "# 转换为 dict\n",
    "res = json.loads(core_catalog_json)\n",
    "if(res['status'] =='not_found'):\n",
    "    print(\"777\")\n",
    "\n",
    "\n",
    "# 过滤治疗方式 = 保守治疗\n",
    "conservative = [item for item in res[\"data\"] if item.get(\"治疗方式\") == \"保守治疗\"]\n",
    "\n",
    "print(conservative[0]['诊断编码'])\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-09-29T02:51:28.186833700Z",
     "start_time": "2025-09-29T02:51:27.273210500Z"
    }
   },
   "id": "c98c082799440e1f",
   "execution_count": 6
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "edefd61f62d904d"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
